#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Created on Thu Nov 21 10:20:32 2013

@author: Casa
"""
import numpy as np
import os
#from scipy.weave import inline

class testset(object):
    '''
    Four value representation
    0:10:2 1:01:1 X:00:0 C:11:3
    '''
    def __init__(self,filename):
        '''
        read testset
        data,size
        '''
        self.name=os.path.basename(filename)
        raw_data=[]
        with open(filename) as f:
            for line in f:
                if len(line)>2:
                    raw_data.append(bytearray(line[:-1]))
        d=np.array(raw_data,np.int)
        d[d==88]=0
        d[d==48]=2
        d[d==49]=1
        self.data=d
#        d=np.empty((len(raw_data),len(raw_data[0])-1),np.int)
#        self.data=d
#        inline('''
#        using namespace std;
#        int m[0xff];m[(int)'0']=2;m[(int)'1']=1;m[(int)'X']=0;
#        for(int i=0;i<Nd[0];i++)
#        {
#            char *p=(char*)raw_data[i];
#            for(int j=0;j<Nd[1];j++)
#                D2(i,j)=m[p[j]];
#        }
#        '''
#        ,['d','raw_data'])

               
    def output(self,filename):
        m={0:'X',1:'1',2:'0'}
        size=self.data.shape
        with open(filename,'w') as f:
            for i in range(size[0]):
                for j in range(size[1]):
                    f.write(m[self.data[i,j]])
                f.write('\n')

if __name__=='__main__':
    from time import clock
    t0=clock()
    ts=testset('s337')
    #ts=testset('F:/work/vlsi-test/TestDataCompression/circutes/s5378')
    print(clock()-t0)
